<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">名称</label>
        <el-input
          v-model="query.name"
          clearable
          placeholder="名称"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <!-- <label class="el-form-item-label">进风口温度</label>
        <el-input
          v-model="query.temperature"
          clearable
          placeholder="进风口温度"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <label class="el-form-item-label">进风口湿度</label>
        <el-input
          v-model="query.humidity"
          clearable
          placeholder="进风口湿度"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        /> -->
        <!-- <label class="el-form-item-label">故障状态</label>
        <el-select
          v-model="query.status"
          clearable
          style="width: 185px"
          placeholder="故障状态"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        >
          <el-option value="0" label="正常" />
          <el-option value="1" label="故障" />
        </el-select> -->
        <!-- <label class="el-form-item-label">缺风状态</label>
        <el-select
          v-model="query.lackWind"
          clearable
          style="width: 185px"
          placeholder="缺风状态"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        >
          <el-option value="0" label="正常" />
          <el-option value="1" label="缺风" />
        </el-select> -->
        <!-- <label class="el-form-item-label">运行变频</label>
        <el-input
          v-model="query.transducer"
          clearable
          placeholder="运行变频"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <label class="el-form-item-label">新风电动阀</label>
        <el-input
          v-model="query.electricallyOperatedValve"
          clearable
          placeholder="新风电动阀"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <label class="el-form-item-label">报警信息</label>
        <el-input
          v-model="query.errorMessage"
          clearable
          placeholder="报警信息"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        /> -->
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          size="small"
          label-width="80px"
        />
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button
            :loading="crud.status.cu === 2"
            type="primary"
            @click="crud.submitCU"
            >确认</el-button
          >
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%"
        @selection-change="crud.selectionChangeHandler"
      >
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="name" label="名称" align="center" />
        <!-- <el-table-column prop="temperature" label="进风口温度" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.temperature">{{ scope.row.temperature }}°C</div>
            <div v-if="scope.row.temperature == null">- -</div>
          </template>
        </el-table-column>
        <el-table-column prop="humidity" label="进风口湿度">
          <template slot-scope="scope">
            <div v-if="scope.row.humidity">{{ scope.row.humidity }}%</div>
            <div v-if="scope.row.humidity == null">- -</div>
          </template>
        </el-table-column>
        <el-table-column prop="transducer" label="运行变频" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.transducer">{{ scope.row.transducer }}m/s</div>
            <div v-if="scope.row.transducer == null">- -</div>
          </template>
        </el-table-column>
        <el-table-column prop="electricallyOperatedValve" label="新风电动阀" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.electricallyOperatedValve">{{ scope.row.electricallyOperatedValve }}%</div>
            <div v-if="scope.row.electricallyOperatedValve == null">- -</div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="故障状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0">正常</span>
            <span v-if="scope.row.status == 1">故障</span>
          </template>
        </el-table-column>
        <el-table-column prop="lackWind" label="缺风状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.lackWind == 0">正常</span>
            <span v-if="scope.row.lackWind == 1">缺风</span>
          </template>
        </el-table-column>  -->
        <el-table-column prop="floor" label="楼层信息"  align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.floor == 1">一楼</span>
            <span v-if="scope.row.floor == 2">二楼</span>
            <span v-if="scope.row.floor == 3">三楼</span>
            <span v-if="scope.row.floor == 4">四楼</span>
            <span v-if="scope.row.floor == 5">五楼</span>
            <span v-if="scope.row.floor == 6">六楼</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="indoorTemperature"
          label="室内温度"
          align="center"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.indoorTemperature">
              {{ scope.row.indoorTemperature }}°C
            </div>
            <div v-if="scope.row.indoorTemperature == null">- -</div>
            <!-- {{ scope.row.indoorTemperature }}°C -->
          </template>
        </el-table-column>
        <el-table-column
          prop="ambientTemperature"
          label="环境温度"
          align="center"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.ambientTemperature">
              {{ scope.row.ambientTemperature }}°C
            </div>
            <div v-if="scope.row.ambientTemperature == null">- -</div>
            <!-- {{ scope.row.ambientTemperature }}°C -->
          </template>
        </el-table-column>
        <!-- <el-table-column prop="errorMessage" label="报警信息"  align="center"/> -->
        <!-- <el-table-column
          v-if="
            checkPer([
              'admin',
              'freshAirVentilatorLog:edit',
              'freshAirVentilatorLog:del',
            ])
          "
          label="操作"
          width="150px"
          align="center"
        >
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudFreshAirVentilatorLog, {
  searchId,
} from "@/api/freshAirVentilatorLog";
import CRUD, { presenter, header, form, crud } from "@crud/crud";
import rrOperation from "@crud/RR.operation";
import crudOperation from "@crud/CRUD.operation";
import udOperation from "@crud/UD.operation";
import pagination from "@crud/Pagination";
import { mapState } from "vuex";

const defaultForm = {
  id: null,
  name: null,
  freshAirVentilatorId: null,
  temperature: null,
  humidity: null,
  status: null,
  lackWind: null,
  transducer: null,
  electricallyOperatedValve: null,
  errorMessage: null,
  createdAt: null,
  updatedAt: null,
  isDeleted: null,
};
export default {
  name: "FreshAirVentilatorLog",
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: "新风设备日志",
      url: "api/freshAirVentilatorLog",
      idField: "id",
      sort: "id,desc",
      crudMethod: { ...crudFreshAirVentilatorLog },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: true,
        reset: true,
      },
    });
  },
  data() {
    return {
      permission: {
        add: ["admin", "freshAirVentilatorLog:add"],
        edit: ["admin", "freshAirVentilatorLog:edit"],
        del: ["admin", "freshAirVentilatorLog:del"],
      },
      rules: {},
      queryTypeOptions: [
        { key: "name", display_name: "名称" },
        { key: "temperature", display_name: "进风口温度" },
        { key: "humidity", display_name: "进风口湿度" },
        { key: "status", display_name: "故障状态" },
        { key: "lackWind", display_name: "缺风状态" },
        { key: "transducer", display_name: "运行变频" },
        { key: "electricallyOperatedValve", display_name: "新风电动阀" },
        { key: "errorMessage", display_name: "报警信息" },
      ],
    };
  },
  computed: {
    ...mapState("hjuser", ["systemSearchInfoId"]),
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true;
    },
    async [CRUD.HOOK.afterRefresh]() {
      if (this.systemSearchInfoId) {
        try {
          const res = await searchId(this.systemSearchInfoId);
          this.crud.data = res.content;
        } finally {
          this.$store.commit("hjuser/updatedsystemSearchInfoId", "");
        }
      }
      return true;
    },
  },
};
</script>

<style scoped>
</style>
